#include "SexyThread.h"
#include <windows.h>

SexyThread::SexyThread(SexyThreadFunction func)
{
	m_threadFunc=func;
}

SexyThread::~SexyThread(void)
{
}

int SexyThread::Start( void * Context )
{
	int res = DE_OK;
	m_threadHandle = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)m_threadFunc,Context,0,NULL);
	if(m_threadHandle==INVALID_HANDLE_VALUE)
		res = DE_ERROR;
	return res;
}

int SexyThread::Wait( unsigned long timeout )
{
	int res = DE_OK;
	DWORD dres = WaitForSingleObject(m_threadHandle,timeout);
	if(dres!=WAIT_OBJECT_0 )
	{
		if(dres==WAIT_TIMEOUT)
			res = DE_TIMEOUT;
		else 
			res = DE_ERROR;
	}
	return res;
}

void SexyThread::Idle( unsigned int t )
{
	Sleep(t);
}
